<?php
/**
 * Created by PhpStorm.
 * User: xiaxiang
 * Date: 2019/3/14
 * Time: 14:30
 */

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;

class UserController
{
    public function login(){

        return view('admin/user/login');
    }
    public function dologin(Request $request){
        $username = $request->get('username');
        $password = $request->get('password');
        $db = DB::table('admin')
            ->where('username',$username)
            ->where('password',$password)
            ->first();
        if($db) {
            $message = "登录成功";
            Session::put(['username' => $username, 'userid' => $db->id]);//创建session
            return redirect(url('admin'))->with('message',$message);
        }
        else{
            $message = "登录失败";
            return redirect(url('admin/login'))->with('message',$message);
        }
    }

    //退出
    public function loginout(){
        Session::flush();
        return redirect(url('admin/login'));
    }
}